#include <iostream>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define ll long long
#define ull unsigned long long;
#define pii pair<ull, ull>
#define N 20000010
char s[N];
stack<char> st;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int v, n;
    cin >> v >> n;
    cin >> (s + 1);
    int maxx = 0, num = 0, ans = 0;
    for (int i = 1; i <= 2 * v; i++)
    {
        //左括号入栈
        if (s[i] == '(')
        {
            st.push('(');
            num++;
        }
        //非左括号弹栈
        else
        {
            st.pop();
        }
        //栈空退出
        if (st.empty())
        {
            break;
        }
        //最大层数为栈剩余元素的总数
        maxx = max(maxx, (int)st.size());
    }
    if (n + 1 < maxx)
        ans = n + 1;
    else
        ans = min(num, maxx + (n - maxx + 1) / 2);
    cout << ans << endl;
    return 0;
}